﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IsmsExplorer.Infrastructure.DomainBase;
using IsmsExplorer.Model.AssetRegister;

namespace IsmsExplorer.Model.RiskRegister {
    public class Threat : EntityBase, ICloneable {
        private int _projectID;
        private Asset _asset;
        private string _threatIdentification;
        private string _threatDescription;
        private int _vulnerability;
        private int _likelihood;
        private int _impact;
        private Treatment _treatment;

        public Threat(int id, Asset asset)
            : base(id) {
            _asset = asset;
        }
        public Threat()
            : this(0, null) {
        }

        public int RiskExposure {
            get { return Vulnerability + Likelihood + Impact; }
        }

        public int Impact {
            get { return _impact; }
            set { _impact = value; }
        }

        public int Likelihood {
            get { return _likelihood; }
            set { _likelihood = value; }
        }

        public int Vulnerability {
            get { return _vulnerability; }
            set { _vulnerability = value; }
        }

        public string ThreatDescription {
            get { return _threatDescription; }
            set { _threatDescription = value; }
        }

        public string ThreatIdentification {
            get { return _threatIdentification; }
            set { _threatIdentification = value; }
        }

        public Asset Asset {
            get { return _asset; }
            set { _asset = value; }
        }

        public int ProjectID {
            get { return _projectID; }
            set { _projectID = value; }
        }

        public Treatment Treatment {
            get { return _treatment; }
            set {
                _treatment = value;
                if (_treatment != null && _treatment.Threat != this) {
                    _treatment.Threat = this;
                }
            }
        }

        /// <summary>
        /// Copies the Threat details and the contained Treatment's. 
        /// NOTE: this is NOT a complete deep copy as the Asset is not cloned.
        /// </summary>
        /// <returns></returns>
        public object Clone() {
            return new Threat {
                Asset = this.Asset,
                ID = this.ID,
                Impact = this.Impact,
                Likelihood = this.Likelihood,
                ProjectID = this.ProjectID,
                ThreatDescription = this.ThreatDescription,
                ThreatIdentification = this.ThreatIdentification,
                Treatment = (this.Treatment != null ? this.Treatment.Clone() as Treatment : null),
                Vulnerability = this.Vulnerability
            };
        }

    } // end public class Threat : EntityBase

}
